<?php
Authenticate::requireTechnic();
if($_SERVER['REQUEST_METHOD']=='GET'){
	$db = Db::getInstance();
	$article = Article::get($_GET['id']);
	View::display('technic/article.edit', array('article'=> $article));
}
else if($_SERVER['REQUEST_METHOD']=='POST'){
	$db = Db::getInstance();
	$db->autocommit(false);
	$query = sprintf("UPDATE Article SET title='%s',description='%s',detail='%s',modifyTime='%s' WHERE id='%s'",
			$db->real_escape_string($_POST['title']),
			$db->real_escape_string($_POST['description']),
			$db->real_escape_string($_POST['detail']),
			date('Y-m-d H:i:s'),
			$db->real_escape_string($_GET['id']));
	if(!$db->query($query)){
		throw new Exception($db->error);
	}
	$db->commit();
	header("Location: old.php?page=technic/article");
}